package hollycrm.com.uip;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by aber on 2017/3/2.
 */

public class Utils {

    private static final String HOST = "127.0.0.1";
    private static final int PORT = 5060;
    private static final String WORK_NO = "1001";
    private static final String DEVICE_NO = "31031";

    public static Config getConfig(Context context, String name,int mode) {
        SharedPreferences sp = context.getSharedPreferences(name,mode);
        return new Config(
                sp.getString("host",HOST),
                sp.getInt("port",PORT),
                sp.getString("workNo",WORK_NO),
                sp.getString("deviceNo",DEVICE_NO)
                );
    }

    public static void saveConfig(Context context,Config config,String name,int mode) {
        SharedPreferences sp = context.getSharedPreferences(name,mode);
        sp.edit().putString("host",config.getHttpHost())
                .putInt("port",config.getPort())
                .putString("workNo",config.getWorkNo())
                .putString("deviceNo",config.getDeviceNo())
                .apply();
    }
}
